﻿package mortal.game.view.systemSetting
{
    import flash.utils.*;
    import mortal.common.sound.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.systemSetting.data.*;
    import mortal.mvc.core.*;

    public class SystemSetting extends Object
    {
        public var hideSetter:SettingItem;
        public var hideSetterType:SettingItem;
        public var playerOnScreen:SettingItem;
        public var playerOnScreenNum:SettingItem;
        public var isHideSkill:SettingItem;
        public var isHideAllEffect:SettingItem;
        public var isHideFlowerEffect:SettingItem;
        public var effectSetterType:SettingItem;
        public var isHideLife:SettingItem;
        public var isHideOterPlayerName:SettingItem;
        public var isHideTitle:SettingItem;
        public var isHideGuildName:SettingItem;
        public var isHideTeamChatBubble:SettingItem;
        public var isHideSystemTips:SettingItem;
        public var isHideRumorTips:SettingItem;
        public var isHideGuildChatPanel:SettingItem;
        public var isRefuseTrade:SettingItem;
        public var isRefuseBeAddToGroup:SettingItem;
        public var isRefuseBeAddToGuild:SettingItem;
        public var isSelectFightToDead:SettingItem;
        public var isNotAutoSelectPet:SettingItem;
        public var isNotAutoSelectPlayer:SettingItem;
        public var isNotAutoSelectMonster:SettingItem;
        public var isShortcutShowSecond:SettingItem;
        public var isLockShortcut:SettingItem;
        public var bgMusic:SettingItem;
        public var effectMusic:SettingItem;
        public var isForbidMusic:SettingItem;
        public var mouseRightUIKey:SettingItem;
        public var mouseRightSceneKey:SettingItem;
        private var _settingDic:Dictionary;
        public var isInitedFromServer:Boolean = false;
        private static var _instance:SystemSetting;

        public function SystemSetting()
        {
            this._settingDic = new Dictionary();
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = new Array();
            _loc_1.push({value:1, text:"屏蔽所有玩家和宠物"});
            _loc_1.push({value:2, text:"屏蔽友方玩家和宠物"});
            _loc_1.push({value:3, text:"屏蔽敌方玩家和宠物"});
            this.hideSetter = new SettingItem("屏蔽玩家和宠物模型", "a", 0);
            this.addSetting(this.hideSetter);
            this.playerOnScreenNum = new SettingItem("单屏内玩家人数显示上限", "b", 20, SettingItem.INT, {min:1, max:200, def:20});
            this.addSetting(this.playerOnScreenNum);
            var _loc_2:* = new Array();
            _loc_2.push({value:1, text:"低"});
            _loc_2.push({value:2, text:"中"});
            _loc_2.push({value:3, text:"高"});
            _loc_2.push({value:4, text:"自动"});
            this.effectSetterType = new SettingItem("", "y2", 4, SettingItem.SELECT, _loc_2);
            this.addSetting(this.effectSetterType);
            this.isHideSkill = new SettingItem("隐藏技能特效", "c");
            this.addSetting(this.isHideSkill);
            this.isHideAllEffect = new SettingItem("屏蔽所有光效", "d");
            this.addSetting(this.isHideAllEffect);
            this.isHideFlowerEffect = new SettingItem("屏蔽送花特效", "d1");
            this.addSetting(this.isHideFlowerEffect);
            this.isHideLife = new SettingItem("屏蔽玩家和怪物血条", "e", 1);
            this.addSetting(this.isHideLife);
            this.isHideOterPlayerName = new SettingItem("隐藏其他玩家名字信息", "f");
            this.addSetting(this.isHideOterPlayerName);
            this.isHideTitle = new SettingItem("屏蔽所有称号", "g");
            this.addSetting(this.isHideTitle);
            this.isHideTeamChatBubble = new SettingItem("屏蔽组队时聊天气泡", "h");
            this.addSetting(this.isHideTeamChatBubble);
            this.isHideSystemTips = new SettingItem("屏蔽系统提示广播", "i");
            this.addSetting(this.isHideSystemTips);
            this.isHideRumorTips = new SettingItem("屏蔽聊天传闻广播", "j");
            this.addSetting(this.isHideRumorTips);
            this.isHideGuildChatPanel = new SettingItem("屏蔽公会聊天面板", "j1");
            this.addSetting(this.isHideGuildChatPanel);
            this.isRefuseTrade = new SettingItem("拒绝他人向我发起交易", "k");
            this.addSetting(this.isRefuseTrade);
            this.isRefuseBeAddToGroup = new SettingItem("拒绝他人邀请我加入队伍", "m");
            this.addSetting(this.isRefuseBeAddToGroup);
            this.isRefuseBeAddToGuild = new SettingItem("拒绝他人邀请我加入公会", "n");
            this.addSetting(this.isRefuseBeAddToGuild);
            this.isSelectFightToDead = new SettingItem("左键选择目标持续攻击", "o");
            this.addSetting(this.isSelectFightToDead);
            this.isNotAutoSelectPlayer = new SettingItem("Tab快捷选取时不选取玩家", "q");
            this.addSetting(this.isNotAutoSelectPlayer);
            this.isNotAutoSelectMonster = new SettingItem("Tab快捷选取时不选取怪物", "r");
            this.addSetting(this.isNotAutoSelectMonster);
            this.isShortcutShowSecond = new SettingItem("技能栏显示技能冷却秒数", "s", 1);
            this.addSetting(this.isShortcutShowSecond);
            this.isLockShortcut = new SettingItem("锁定快捷栏", "t");
            this.addSetting(this.isLockShortcut);
            this.bgMusic = new SettingItem("音乐", "u", 35, SettingItem.INT);
            this.effectMusic = new SettingItem("音效", "v", 15, SettingItem.INT);
            this.isForbidMusic = new SettingItem("静音", "w");
            this.addSetting(this.bgMusic);
            this.addSetting(this.effectMusic);
            this.addSetting(this.isForbidMusic);
            this.isHideGuildName = new SettingItem("屏蔽公会职位称号", "x");
            this.addSetting(this.isHideGuildName);
            this.hideSetterType = new SettingItem("", "y", 2, SettingItem.SELECT, _loc_1);
            this.addSetting(this.hideSetterType);
            this.mouseRightUIKey = new SettingItem("鼠标右键UI面板等同双击", "z", 1);
            this.addSetting(this.mouseRightUIKey);
            this.mouseRightSceneKey = new SettingItem("左键选择右键攻击移动", "a1");
            this.addSetting(this.mouseRightSceneKey);
            this.playerOnScreen = new SettingItem("单屏内玩家人数显示上限", "a2", 1);
            this.addSetting(this.playerOnScreen);
            return;
        }// end function

        private function addSetting(param1:SettingItem) : void
        {
            this._settingDic[param1.key] = param1;
            return;
        }// end function

        public function resetToDefault() : void
        {
            var _loc_1:SettingItem = null;
            for each (_loc_1 in this._settingDic)
            {
                
                _loc_1.resetToDefault();
            }
            return;
        }// end function

        public function updateToServer() : void
        {
            var _loc_1:SettingItem = null;
            for each (_loc_1 in this._settingDic)
            {
                
                _loc_1.updateToServer();
            }
            return;
        }// end function

        public function recover(param1:Boolean = false) : void
        {
            var _loc_2:SettingItem = null;
            for each (_loc_2 in this._settingDic)
            {
                
                if (param1 || _loc_2 != this.bgMusic && _loc_2 != this.effectMusic && _loc_2 != this.isForbidMusic)
                {
                    _loc_2.recover();
                }
            }
            return;
        }// end function

        public function save() : void
        {
            var _loc_1:* = new Object();
            _loc_1.type = SystemSettingType.SystemSetting;
            _loc_1.value = SystemSetting.instance.getServerStr();
            _loc_1.isNotTip = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

        public function getServerStr() : String
        {
            var _loc_2:SettingItem = null;
            var _loc_1:* = new Object();
            for each (_loc_2 in this._settingDic)
            {
                
                _loc_1[_loc_2.key] = _loc_2.value;
            }
            return JSON.stringify(_loc_1);
        }// end function

        public function initFromServerStr(param1:String) : void
        {
            var _loc_3:String = null;
            var _loc_4:SettingItem = null;
            this.isInitedFromServer = true;
            if (!param1)
            {
                return;
            }
            var _loc_2:* = JSON.parse(param1);
            for (_loc_3 in _loc_2)
            {
                
                _loc_4 = this._settingDic[_loc_3];
                if (_loc_4)
                {
                    _loc_4.value = int(_loc_2[_loc_3]);
                }
            }
            SoundManager.instance.musicVolume = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (SystemSetting.instance.bgMusic.displayValue / 100);
            SoundManager.instance.effectSoundVolune = SystemSetting.instance.isForbidMusic.displayValue ? (0) : (SystemSetting.instance.effectMusic.displayValue / 100);
            return;
        }// end function

        public static function get instance() : SystemSetting
        {
            if (!_instance)
            {
                _instance = new SystemSetting;
            }
            return _instance;
        }// end function

    }
}
